﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class admin_adminQx : System.Web.UI.Page
{
    public string nowuserid = "";
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            init();
        }
    }
    public void init() { 
        if(Request["userid"]!=null && Request["userid"].ToString().Trim().Length>0){
            nowuserid = Request["userid"].ToString().Trim();
        }
    }
    //选择要分配权限的用户列表
    public void getUsers() {
        StringBuilder sb = new StringBuilder();
        //获取人员
        DataTable dt = DB.getDataTable("select * from admin where admin<>'qiang' and admin<>'admin'");
        if (dt != null && dt.Rows.Count > 0) {
            for (int i = 0; i < dt.Rows.Count; i++) {
                sb.Append("<option value='" + dt.Rows[i]["id"].ToString()+"'");
                if (nowuserid.Equals(dt.Rows[i]["id"].ToString())) {
                    sb.Append(" selected ");
                }
                sb.Append(">" + dt.Rows[i]["admin"].ToString() + "</option>");
            }
        }
        Response.Write(sb.ToString());
    }
    //生成树
    public void getTree() {
        if (nowuserid.Trim().Length > 0)
        {
            StringBuilder sb = new StringBuilder();
            //获取栏目
            DataTable dt = DB.getDataTable("select * from channel");
            if (dt != null && dt.Rows.Count > 0)
            {
                Object obj;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    sb.Append("tree.nodes[\"" + dt.Rows[i]["father_id"].ToString() + "_" + dt.Rows[i]["channel_id"].ToString() + "\"] = \"text:<input type=checkbox id=" + dt.Rows[i]["channel_id"].ToString() + " name=qxs value=" + dt.Rows[i]["channel_id"].ToString());
                    //判断当前用户是否有此栏目的权限
                    obj = DB.getObject("select count(*) from admin_qx where adminId=" + nowuserid + " and channelId=" + dt.Rows[i]["channel_id"].ToString());
                    if (obj != null && Int32.Parse(obj.ToString()) > 0)
                    {
                        sb.Append(" checked ");
                    }
                    sb.Append(" />" + dt.Rows[i]["name"].ToString() + ";method:setValue('" + dt.Rows[i]["channel_id"].ToString() + "')\"; ");
                }
            }
            Response.Write(sb.ToString());
        }
    }
}
